/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package net.wofly.right.repository;

import net.wofly.right.domain.FuncList;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface FuncListRepository
        extends PagingAndSortingRepository<FuncList, String>, JpaSpecificationExecutor<FuncList> {
    
    @Override
    Page<FuncList> findAll(Specification<FuncList> specification, Pageable pageable);
    
    List<FuncList> findByFuncUrl(String funcUrl);
    
    Page<FuncList> findByFuncNameAndFuncType(String funcName, Integer funcType, Pageable pageable);

    /**
     * 根据角色ID和功能类型获取功能列表
     *
     * @return
     */
    @Query(value = "SELECT fl FROM FuncList fl WHERE fl.funcType = :funcType")
    Page<FuncList> findPageByFuncType(@Param(value = "funcType")Integer funcType, Pageable pageable);
}